package com.example.young.peopleaccommodationms;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{


    public Button cancel_btn;
    public Button login_btn;
    public Button finish_btn;
    public Button to_second_btn;
    public EditText account_edit;
    public EditText pwd_edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        account_edit = (EditText) findViewById(R.id.accountEdit);
        pwd_edit = (EditText) findViewById(R.id.pwdEdit);
        cancel_btn = (Button) findViewById(R.id.cancel);
        login_btn = (Button) findViewById(R.id.login);
        finish_btn = (Button) findViewById(R.id.destory);
        to_second_btn = (Button) findViewById(R.id.to_second_activity);

        cancel_btn.setOnClickListener(this);
        login_btn.setOnClickListener(this);
        finish_btn.setOnClickListener(this);
        to_second_btn.setOnClickListener(this);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.add_item:
                Toast.makeText(this, "you clicked add itemMenu", Toast.LENGTH_SHORT).show();
                break;
            case R.id.remove_item:
                Toast.makeText(this,"you clicked remove itemMenu",Toast.LENGTH_SHORT).show();
                break;
            default:
        }
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.login:
//                String username = account_edit.getText().toString();
//                String password = pwd_edit.getText().toString();
//                if (username.equals("root") && password.equals("123")){
//                    Intent intent = new Intent(MainActivity.this,HomePage.class);
//                    startActivity(intent);
//                }
                Intent intent = new Intent(MainActivity.this,HomePage.class);
                startActivity(intent);
                break;
            case R.id.cancel:
                account_edit.setText("");
                pwd_edit.setText("");
                break;
            case R.id.destory:
                finish();
                break;
            case R.id.to_second_activity:
//                跳转到第二个ac
//                Intent intent_to_second_activity = new Intent("com.example.young.peopleAccommodation.action_start");
//                startActivity(intent_to_second_activity);
//                打开系统浏览器
//                Intent intent1 = new Intent(Intent.ACTION_VIEW);
//                intent1.setData(Uri.parse("http://www.baidu.com"));
//                打开拨号界面
//                Intent intent1 = new Intent(Intent.ACTION_DIAL);
//                intent1.setData(Uri.parse("tel:10086"));
                String data = "Hello secondAc";
                Intent intent1 = new Intent(MainActivity.this, SecondActicity.class);
                intent1.putExtra("extra_data", data);
//                startActivity(intent1);
                startActivityForResult(intent1,1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    String return_Data = data.getStringExtra("data_return");
                    Log.d("FirstActivity", return_Data);
                }
                break;
            default:

        }
    }
}
